package com.droidbank;

import java.util.Random;

import com.droidbank.model.DataModel;
import com.droidbank.util.UIUtil;
import com.droidbank.model.Account;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;


public class SettingsActivity extends ListActivity {

	private DataModel dm;
	
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings_layout);

        dm = (DataModel)this.getApplication();
        
        String items[] = new String[]{"Export to SD", "Import from SD", "Add Account", "Remove Account"};
        
        
        ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);  

 
        setListAdapter(adapter);
    }
    
    protected void onListItemClick(ListView l, View v, int position, long id) 
	{
		super.onListItemClick(l, v, position, id);

		
		switch(position)
		{
			case 0:
		    	UIUtil.showActivitySaveLoad(this, dm, "saveXML", true, true);
				break;
			case 1:
		    	UIUtil.showActivitySaveLoad(this, dm, "loadXML", false, true);
				break;
			case 2:
				int x = new Random().nextInt(1000);
				dm.getAccounts().add(new Account("Hello" +x, x));
				break;
				
		}
		
	}
}

